﻿/*
 * 淡云孤月 2018-05-24 17:43:05
 */
; function Eject() {
    this.defaults = {
        elm: null,
        width: '360px',
        height: '100%',
        speed: '.3s',
        // 上t 下d 左l 右r
        vector: 'l',
        obj: 'eject'
    };
    this.options = {};
    this.init = function (ops) {
        this.options = $.extend({}, this.defaults, ops);
        $(this.options.elm).css({ "width": this.options.width, "height": this.options.height, "position": "fixed", "background-color": "#fff", "z-index": 9999 });
        var width = parseInt($(this.options.elm).css("width"));
        var height = parseInt($(this.options.elm).css("height"));
        switch (this.options.vector) {
            case "t":
                $(this.options.elm).css({ "left": 0, "top": -height, "transition": "top " + this.options.speed });
                break;
            case "d":
                $(this.options.elm).css({ "left": 0, "bottom": -height, "transition": "bottom " + this.options.speed });
                break;
            case "l":
                $(this.options.elm).css({ "left": -width, "top": 0, "transition": "left " + this.options.speed });
                break;
            case "r":
                $(this.options.elm).css({ "right": -width, "top": 0, "transition": "right " + this.options.speed });
                break;
            default:
                $(this.options.elm).css({ "left": -width, "top": 0, "transition": "left " + this.options.speed });
                break;
        }
    };
    this.open = function () {
        var width = parseInt($(this.options.elm).css("width"));
        var height = parseInt($(this.options.elm).css("height"));
        var backgroundDiv = '<div class="eject_back_div" style="width:100%;height:100%;background-color:rgba(0,0,0,.4);z-index:9998;display:block;top:0;left:0;position: fixed;" onclick="javascript:{ ' + this.options.obj + '.close(); }"></div>';
        $('body').append(backgroundDiv);
        $(this.options.elm).show();
        switch (this.options.vector) {
            case "t":
                $(this.options.elm).css({ "top": 0, "border-bottom": "1px #ccc solid" });
                break;
            case "d":
                $(this.options.elm).css({ "bottom": 0, "border-top": "1px #ccc solid" });
                break;
            case "l":
                $(this.options.elm).css({ "left": 0, "border-right": "1px #ccc solid" });
                break;
            case "r":
                $(this.options.elm).css({ "right": 0, "border-left": "1px #ccc solid" });
                break;
            default:
                $(this.options.elm).css({ "left": 0, "border-right": "1px #ccc solid" });
                break;
        }
    };
    this.close = function () {
        var width = parseInt($(this.options.elm).css("width"));
        var height = parseInt($(this.options.elm).css("height"));
        $('.eject_back_div').remove();
        switch (this.options.vector) {
            case "t":
                $(this.options.elm).css({ "top": -height });
                break;
            case "d":
                $(this.options.elm).css({ "bottom": -height });
                break;
            case "l":
                $(this.options.elm).css({ "left": -width });
                break;
            case "r":
                $(this.options.elm).css({ "right": -width });
                break;
            default:
                $(this.options.elm).css({ "left": -width });
                break;
        }
    };
};
